<?php

class PackerFilter extends FilterIterator {
    public function __construct (Iterator $iter) {
        parent::__construct($iter);
    }
    
    public function accept () {
        $file = $this->getInnerIterator()->current();
        
        if(strstr($file, '.svn') || strstr($file, 'nbproject')) return false;
        
        return true;
    }
}

$iter = new RecursiveDirectoryIterator('./');
$iter = new RecursiveIteratorIterator($iter);
$iter = new PackerFilter($iter);

$ph = new Phar('ServiceEngine.phar');

foreach($iter as $file) {
    echo 'Adding file: '.$file.'<br/>';
    $ph->addFile($file, str_replace(array('./', '.\\'), '', $file));
}

$ph->setStub("
    <?php
    require 'phar://ServiceEngine.phar/se.php';
    __HALT_COMPILER();
    ?>
");